package algorithm.leetcode.I201to400;

public class Q209 {

    public int minSubArrayLen(int target, int[] nums) {
        int left = 0, right = 0, sum = 0, size = Integer.MAX_VALUE;

        while (right < nums.length) {
            sum += nums[right];
            while (left <= right && sum >= target) {
                size = Math.min(size, right-left+1);
                sum -= nums[left];
                left++;
            }
            right++;
        }

        return size == Integer.MAX_VALUE ? 0 : size;
    }

    public static void main(String[] args) {
        Q209 q209 = new Q209();
//        System.out.println(q209.minSubArrayLen(7, new int[]{2, 3, 1, 2, 4, 3}));
        System.out.println(q209.minSubArrayLen(99, new int[]{1,4,4}));
    }
}
